import axios from '@/utils/request'

/*
  获取评论列表
  offset 第一页数据应该是null
  offset  第二页值应该是第一页返回的值
 */
export const getCommentList = (articleId, offset) => {
  return axios({
    method: 'GET',
    url: '/v1_0/comments',
    params: {
      type: 'a',
      source: articleId,
      offset,
      limit: 10
    }
  })
}

/*
  获取评论列表
  offset 第一页数据应该是null
  offset  第二页值应该是第一页返回的值
 */
export const getCommentReply = (commentId, offset) => {
  return axios({
    method: 'GET',
    url: '/v1_0/comments',
    params: {
      type: 'c',
      source: commentId,
      offset,
      limit: 10
    }
  })
}

/**
 * 对文章进行评论
 * @param {*} articleId 文章编号
 * @param {*} content 评论内容
 */
export const addComment = (articleId, content) => {
  return axios({
    method: 'post',
    url: '/v1_0/comments',
    data: {
      target: articleId,
      content
    }
  })
}

/**
 * 添加文章评论回复
 * @param {*} commentId 评论id
 * @param {*} content 内容
 * @param {*} articleId 文章id
 */
export const addCommentReply = (commentId, content, articleId) => {
  return axios({
    method: 'post',
    url: '/v1_0/comments',
    data: {
      target: commentId,
      content,
      art_id: articleId
    }
  })
}

/**
 * 对文章评论进行点赞
 * @param {*} commentId 评论id
 */
export const addCommentLike = commentId => {
  return axios({
    method: 'post',
    url: '/v1_0/comment/likings',
    data: {
      target: commentId
    }
  })
}

/**
   * 取消文章评论的点赞
   * @param {*} commentId 评论id
   */
export const deleteCommentLike = commentId => {
  return axios({
    method: 'delete',
    url: '/v1_0/comment/likings/' + commentId
  })
}
